<?php
namespace Web\Controller;
use Think\Controller;
class CurrcateController extends UserController {

    function __construct()
    {
        parent::__construct();
        $this->M_curr_cate = M('Curr_cate');
    }

    public function index(){
        $data['uid'] = $this->uid;
        $count = $this->M_curr_cate->where('uid = '.$this->uid)->order('sort asc')->count();
        $page = $this->page($count,15);
        $list = $this->M_curr_cate->where('uid = '.$this->uid)->limit($page['f'].",".$page['l'])->order('sort asc')->select();
        $this->assign('list',$list);
        $this->display();
    }

    public function edit(){
        $id = I('get.id',0,'int');
        if(!empty($id)){
            $info = $this->M_curr_cate->find($id);
            $this->assign('info',$info);
        }
        if(IS_POST){
            $this->M_curr_cate->curr_cate_name = I('post.curr_cate_name');
            $this->M_curr_cate->sort = I('post.sort',0,'intval');
            if($id){
                if($this->M_curr_cate->save())
                die($this->success('修改成功',U('currcate/index')));
            }else{
                $this->M_curr_cate->uid = $this->uid;
                if($this->M_curr_cate->add())
                die($this->success('添加成功',U('currcate/index')));
            }
        }
        $this->display();
    }


    public function is_show(){
        if(!IS_AJAX)
            die($this->ajaxReturn('对不起，您不是ajax访问'));

        $id = I('get.id',0,'intval');
        if(!$id)
            die($this->ajaxReturn('参数错误！'));
        $info = $this->M_curr_cate->find($id);
        $is_show = $info['is_show']?0:1;
        $this->M_curr_cate->is_show = $is_show;
        $this->M_curr_cate->save();
        $is_show?$this->ajaxReturn(array('result'=>'yes')):$this->ajaxReturn(array('result'=>'no'));
    }





}